//
//  HomeViewItemCell.m
//  StormWatch
//
//  Created by 王岩 on 2024/8/30.
//

#import "HomeViewItemCell.h"

@implementation HomeViewItemCell

- (void)updateTheme {
    self.gradientLayer.colors = [ThemeManager sharedInstance].gradientColors;
    
    self.nameLab.textColor = [ThemeManager sharedInstance].textColor;
    
    self.valueLab.textColor = [ThemeManager sharedInstance].textColor;

}

- (void)updateValue {
    if (self.row == 0) {
        self.nameLab.text = SWString(@"Sport data");
    }else if (self.row == 1) {
        self.nameLab.text = SWString(@"Sleep");
    }else if (self.row == 2) {
        self.nameLab.text = SWString(@"Heart rate");
    }else if (self.row == 3) {
        self.nameLab.text = SWString(@"Blood oxygen");
    }
}

- (void)drawCorner:(UIRectCorner)corner {
    [self fsj_setCorner:corner radius:10];
    
    if (corner == UIRectCornerTopLeft) {
        if ([ThemeManager sharedInstance].themeValue == Theme_Default) {
            self.iconView.image = S_imageNamed(@"home_icon_sport");
        }else {
            self.iconView.image = [S_imageNamed(@"home_icon_sport") imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
            self.iconView.tintColor = [UIColor whiteColor];
        }
        self.nameLab.text = SWString(@"Sport data");
    }else if (corner == UIRectCornerTopRight) {
        if ([ThemeManager sharedInstance].themeValue == Theme_Default) {
            self.iconView.image = S_imageNamed(@"home_icon_sleep");
        }else {
            self.iconView.image = [S_imageNamed(@"home_icon_sleep") imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
            self.iconView.tintColor = [UIColor whiteColor];
        }
        self.nameLab.text = SWString(@"Sleep");
    }else if (corner == UIRectCornerBottomLeft) {
        self.iconView.image = S_imageNamed(@"home_icon_heart");
        self.nameLab.text = SWString(@"Heart rate");
    }else if (corner == UIRectCornerBottomRight) {
        self.iconView.image = S_imageNamed(@"home_icon_oxygen");
        self.nameLab.text = SWString(@"Blood oxygen");
    }
    
}

- (CAGradientLayer *)gradientLayer {
    if (!_gradientLayer) {
        _gradientLayer = [[CAGradientLayer alloc] init];
        _gradientLayer.frame = CGRectMake(0, 0, (kScreenWidth - 20 - 15) / 2.0, (kScreenWidth - 20 - 15) / 2.0);
        _gradientLayer.startPoint = CGPointMake(1, 1);
        _gradientLayer.endPoint = CGPointMake(0, 0);
    }
    return _gradientLayer;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self.contentView.layer insertSublayer:self.gradientLayer atIndex:0];
    // Initialization code
}

@end
